package leetcode4;
import java.security.KeyStore;
import java.util.*;
public class Day7 {



    public String[][] groupAnagrams (String[] strs) {
        // write code here
        Map<String,List<String>> map = new HashMap<>();
        for(int i=0;i<strs.length;i++) {
            char[] t = strs[i].toCharArray();
            Arrays.sort(t);
            String s = new String(t);
            if(!map.containsKey(s)) {
                map.put(s,new ArrayList<>());
            }
            List<String> list = map.get(s);
            list.add(strs[i]);
            map.put(s,list);
        }
        String[][] ret = new String[map.size()][];
        int k=0;
        for(Map.Entry<String, List<String>> listSet : map.entrySet()) {
            List<String> value = listSet.getValue();
//            for(int i=0;i<value.size();i++) {
//                ret[k][i] = value.get(i);
//            }
//            k++;
            ret[k++] = value.toArray(new String[0]);
        }
        return ret;
    }
}
